package edu.mju.serviceutils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * controller向前端返回的数据格式，状态等
 */
@Data
public class ResponseCode {

    private Boolean status;
    private Integer code ;
    private String message;
    private Map<String,Object> data = new HashMap<>();

    private ResponseCode() {
    }


    public ResponseCode status(Boolean status) {
        this.setStatus(status);
        return this;
    }

    public ResponseCode code(Integer code){
        this.setCode(code);
        return this;
    }

    public ResponseCode message(String code){
        this.setMessage(code);
        return this;
    }

    public ResponseCode data(Map<String,Object> map){
        this.setData(map);
        return this;
    }

    public ResponseCode data(String key ,Object value){
        this.data.put(key,value);
        return this;
    }
    /**
     * @return 成功返回的结果
     */
    public static ResponseCode success(){
        ResponseCode responseCode = new ResponseCode();
        responseCode.setStatus(true);
        responseCode.setCode(ResponseStatus.SUCCESS);
        responseCode.setMessage("成功返回!");
        return responseCode;
    }

    /**
     * @return 错误返回的结果
     */
    public static ResponseCode error(){
        ResponseCode responseCode = new ResponseCode();
        responseCode.setStatus(false);
        responseCode.setCode(ResponseStatus.ERROR);
        responseCode.setMessage("错误返回!");
        return responseCode;
    }


}
